<?php
session_start();


if(isset($_GET['lang'])){
  $lang = trim($_GET['lang']);
  
  // register the session and set the cookie
  $_SESSION['lang'] = $lang;
  
  setcookie("lang", $lang, time() + (3600 * 24 * 30));
  
  
}else if(isset($_SESSION['lang'])){
  $lang = trim($_SESSION['lang']);
  setcookie("lang", $lang, time() + (3600 * 24 * 30));
}else if(isset($_COOKIE['lang'])){
  $lang = trim($_COOKIE['lang']);
  $_SESSION['lang'] = $lang;
}else{
  $lang = 'en';
  $_SESSION['lang'] = $lang;
  setcookie("lang", $lang, time() + (3600 * 24 * 30));
}

switch ($lang) {
  case 'en':
  $lang_file = 'lang.en.php';
  break;

  case 'th':
  $lang_file = 'lang.th.php';
  break;

  default:
  $lang_file = 'lang.en.php';

}

include_once 'languages/'.$lang_file;
?>